package org.watchrecords.managers;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;

import org.watchrecords.dbo.CellRecord;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.wideplay.warp.persist.Transactional;
import com.wideplay.warp.persist.dao.Finder;

public class CellLogManager {
    private Provider<EntityManager> emProvider;
    
    protected CellLogManager() {}

    @Inject
    public CellLogManager(Provider<EntityManager> emProvider) {
        this.emProvider = emProvider;
    }
    
    public CellRecord getCellRecord(int id) {
        return emProvider.get().find(CellRecord.class, id);
    }
    
    @Transactional
    public void saveCellRecord(CellRecord record) {
        if (record.getId() == null) {
            record.setCreated(new Date());
        }
        
        emProvider.get().persist(record);
    }
    
    @Finder(namedQuery = "getCellRecords")
    public List<CellRecord> getCellRecords() {
        throw new AssertionError();
    }

}
